package org.Image.management.ViewService.utils;


import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import lombok.extern.slf4j.Slf4j;
import org.Image.management.ViewCofig.file.IconPath;

import java.io.IOException;
import java.net.URL;
import java.util.function.BiConsumer;

@Slf4j
public class informationalTips {

    private informationalTips() {
    }

    //  提示框
    //  提示框动画
    public static void setPrompt(Label prompt, String str) {
        setPrompt(prompt, str, 20);
    }

    public static void setPrompt(Label prompt, String str, int fontSize) {
        prompt.setStyle("-fx-font-size: " + fontSize + "px;"); // 设置字体大小

        prompt.setText(str);
        prompt.setVisible(true);
        Timeline t = new Timeline();
        KeyFrame frame1 = new KeyFrame(Duration.seconds(0), new KeyValue(prompt.opacityProperty(), 0)
                , new KeyValue(prompt.translateYProperty(), 0)
        );
        KeyFrame frame2 = new KeyFrame(Duration.seconds(0.5), new KeyValue(prompt.opacityProperty(), 1)
                , new KeyValue(prompt.translateYProperty(), 15)
        );

        KeyFrame frame3 = new KeyFrame(Duration.seconds(1.5), new KeyValue(prompt.opacityProperty(), 1)
                , new KeyValue(prompt.translateYProperty(), 15)
        );


        KeyFrame frame4 = new KeyFrame(Duration.seconds(2), new KeyValue(prompt.opacityProperty(), 0)
                , new KeyValue(prompt.translateYProperty(), 0)
        );
        t.getKeyFrames().addAll(frame1, frame2, frame3, frame4);
        t.play();
    }

    public static void textEntryDialogBox(StageStyle style, String Text, String Title, boolean isRemoveButton, BiConsumer<ActionEvent, TextInputDialog> value) {
        textEntryDialogBox(IconPath.ATTACHMENT.getIconURL(), style, Text, Title, isRemoveButton, value);
    }


    public static void textEntryDialogBox(URL WindowIcon, StageStyle style, String Text, String Title, boolean isRemoveButton, BiConsumer<ActionEvent, TextInputDialog> value) {
        try {
            textEntryDialogBox(new Image(WindowIcon.openStream()), style, Text, Title, isRemoveButton, value);
        } catch (IOException e) {
            log.info("textEntryDialogBox 加载图标失败");
        }
    }

    public static void textEntryDialogBox(Image WindowIcon, StageStyle style, String Text, String Title, boolean isRemoveButton, BiConsumer<ActionEvent, TextInputDialog> value) {
        // 设置并添加 获取图片
        TextInputDialog inputDialog = new TextInputDialog();
        inputDialog.initStyle(style);
        inputDialog.setTitle(Title);
        inputDialog.setHeaderText(Text);
        // 设置图标
        Stage stage = (Stage) inputDialog.getDialogPane().getScene().getWindow();
        stage.getIcons().add(WindowIcon); // 替换为你的图标路径

        if (isRemoveButton) {
            inputDialog.getDialogPane().getButtonTypes().remove(1);
        }
        Button ok = (Button) inputDialog.getDialogPane().lookupButton(ButtonType.OK);
        ok.setOnAction(event -> value.accept(event, inputDialog));
        inputDialog.show();
    }

    public static void AlertDialogBox(Alert.AlertType error, Image WindowIcon, String ContentText, String HeaderText, String Title, EventHandler<ActionEvent> value) {
        Alert alert = new Alert(error);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.getIcons().add(WindowIcon);
        alert.setTitle(Title);
        alert.setHeaderText(HeaderText);
        alert.setContentText(ContentText);
        Button ok = (Button) alert.getDialogPane().lookupButton(ButtonType.OK);
        ok.setOnAction(value);
        alert.showAndWait();
    }

    public static void AlertDialogBox(Alert.AlertType error, Image WindowIcon, String ContentText, String HeaderText, String Title) {
        AlertDialogBox(error, WindowIcon, ContentText, HeaderText, Title, event -> {
        });
    }

    public static void AlertDialogBox(Alert.AlertType error, URL WindowIcon, String ContentText, String HeaderText, String Title, EventHandler<ActionEvent> value) {
        try {
            AlertDialogBox(error, new Image(WindowIcon.openStream()), ContentText, HeaderText, Title, value);
        } catch (IOException e) {
            log.info("AlertDialogBox 加载图标失败");
        }
    }

    public static void AlertDialogBox(Alert.AlertType error, URL WindowIcon, String ContentText, String HeaderText, String Title) {
        AlertDialogBox(error, WindowIcon, ContentText, HeaderText, Title, (event) -> {
        });
    }
}
